using JEngine.Core;
using System;
using UnityEngine;

namespace CL
{
	public class CLInit : MonoBehaviour
	{
		private void Start()
		{
			DontDestroyOnLoad(gameObject);
			this.StartAsync();
		}

		private void StartAsync()
		{
			CLWorld.Instance.AddSingleton<CLLogger>().Log = new CLUnityLogger();
			CLWorld.Instance.AddSingleton<CLTimeInfo>();
			CLWorld.Instance.AddSingleton<ObjectPool>();
			CLWorld.Instance.AddSingleton<IdGenerater>();
			CLWorld.Instance.AddSingleton<CLEntitySystemSingleton>();
			CLWorld.Instance.AddSingleton<CLFiberManager>();
		}

		private void Update()
		{
			CLTimeInfo.Instance.Update();
			CLFiberManager.Instance.Update();
		}

		private void LateUpdate()
		{
			CLFiberManager.Instance.LateUpdate();
		}

		private void OnApplicationQuit()
		{
			CLWorld.Instance.Dispose();
		}

	}
}
